


Date.prototype.format = function(fmt) {
    var o = {
        "M+" : this.getMonth()+1,                 //月份
        "d+" : this.getDate(),                    //日
        "h+" : this.getHours(),                   //小时
        "m+" : this.getMinutes(),                 //分
        "s+" : this.getSeconds(),                 //秒
        "q+" : Math.floor((this.getMonth()+3)/3), //季度
        "S"  : this.getMilliseconds()             //毫秒
    };
    if(/(y+)/.test(fmt)) {
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    }
    for(var k in o) {
        if(new RegExp("("+ k +")").test(fmt)){
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        }
    }
    return fmt;
}
//获取id
var ss= getUrlParam('id');

//获取url中的参数
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}

var vm= new Vue({
    el:"#ljw",
    data:{
        listPr:"",
        listPl:[],
        skje:0,
        ktuihuo:0,
        listck:[],
    },
    methods:{
        showPr(){
            axios.get('/purchase/showPr',{
                params:{
                    code:ss
                }
            }).then(response=>{
                var dto = response.data.obj
                vm.listPr=dto
                console.log(vm.listPr)

            })
        },
        showPl(){
            axios.get('/purchase/listPl',{
                params: {
                    pid:ss,
                }
            }).then(res=>{
                vm.listPl=res.data.obj
                for(var i=0 ;i<vm.listPl.length;i++){
                    vm.skje=vm.skje+vm.listPl[i].total
                }
                console.log(vm.listPl)
            }).catch(err=>{

            })
        },
        tj(){
            var pr={
                id:ss,
                orderStaId:6
            }
            axios.post('/purchase/updaPr',pr,{

            }).then(res=>{
                var ck={
                    relCode:ss,
                    type:22,
                    status:1,
                    houseId:this.listPr.houseId,
                    single:getCookie(),
                    subDate:new Date().format("yyyy-MM-dd hh:mm:ss"),
                    preDate:this.listPr.returnDate,
                    remark:this.listPr.remark
                }
                var json={
                    stock_order:ck,
                    list:this.listPl
                }
                axios.post('/wares/addStock_order',json,{

                }).then(res=>{
                    alert("提交成功")
                    location.reload()
                })
            })
        },
        ck(){
            var qa={
                id:ss,
                orderStaId:3
            }
            JSON.stringify(qa)
            axios.post('/purchase/updaPr',qa,{
                'Content-Type':'multipart/form-data'
            }).then(res=>{
                var crk={
                    relCode:ss,
                    pageNum:1,
                    pageSize:1,
                }
                JSON.stringify(crk)
                axios.post('/wares/getStock_order',crk,{
                    'Content-Type':'multipart/form-data'
                }).then(res=>{
                    console.log(res.data)
                    vm.listck=res.data.obj.list
                    var code=vm.listck[0].code
                    var ck={
                        bStatus:this.listPr.orderSta,
                        status:2,
                        code:code,
                        type:22,
                        single:getCookie(),
                        subDate:new Date().format("yyyy-MM-dd hh:mm:ss"),


                    }
                    JSON.stringify(ck)
                    axios.post('/wares/nextStock_order',ck,{
                        'Content-Type':'multipart/form-data'
                    }).then(res=>{
                        alert("出库成功")
                        location.reload()
                    })
                })
            })
        },
        isShow(v){
            for (var i=2;i<quan.length;i++){
                if (v==quan[i])return true
            }
            return false
        },
        fh(){
            var qa={
                id:ss,
                orderStaId:15
            }
            JSON.stringify(qa)
            axios.post('/purchase/updaPr',qa,{
                'Content-Type':'multipart/form-data'
            }).then(res=>{
                var crk={
                    relCode:ss,
                    pageNum:1,
                    pageSize:1,
                }
                JSON.stringify(crk)
                axios.post('/wares/getStock_order',crk,{
                    'Content-Type':'multipart/form-data'
                }).then(res=>{
                    console.log(res.data)
                    vm.listck=res.data.obj.list
                    var code=vm.listck[0].code
                    var fh={
                        bStatus:this.listPr.orderSta,
                        status:15,
                        code:code,
                        type:22,
                        verifier:getCookie(),
                        verifyDate:new Date().format("yyyy-MM-dd hh:mm:ss"),
                    }
                    JSON.stringify(fh)
                    axios.post('/wares/nextStock_order',fh,{
                        'Content-Type':'multipart/form-data'
                    }).then(res=>{
                        var json={
                            relcode:ss,
                            userId:this.listPr.supplierId,
                            amount:this.listPr.price,//金额
                            type:2,
                            account:1,
                            receTime:new Date().format("yyyy-MM-dd hh:mm:ss"),
                            receiptSta:2,
                            // //制单人
                            maker:this.listPr.single,
                            // //支付方式
                            payway:16,
                            // //备注
                            remarks:this.listPr.remark
                            //
                            //
                            // remark:"这是点击入库生成的付款单",
                        }
                        var data = new FormData()
                        data.append('json',JSON.stringify(json))
                        axios.post('/finance/addReceipt_order',data,{
                            'Content-Type':'multipart/form-data'
                        }).then(res=>{
                            alert("发货成功")
                            location.reload();
                        })
                    })
                })
            })
        },

    },
    mounted(){
        this.showPr();
        this.showPl()
    },

})